<?php


  function get_webcitation($url, $webcite_email) {
    $url = "http://www.webcitation.org/archive?url=".urlencode($url)."&email=";
    $url .= $webcite_email;
    $ch = curl_init();

    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);

    $html = curl_exec ($ch);
    if (empty($html)) {
      return "<strong>Error:</strong> Connection Timeout";
    }
    preg_match_all ("/a[\s]+[^>]*?href[\s]?=[\s\"\']+".
                    "(.*?)[\"\']+.*?>"."([^<]+|.*?)?<\/a>/", 
                    $html, $matches);
        
    $matches = $matches[1];
    $list = array();

    foreach($matches as $var)
    {    
      if (strpos($var, "http://www.webcitation.org") === 0) {
        curl_close ($ch);
        return $var;
      }
    }
  }
  
  function get_tinyurl($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"http://tinyurl.com/create.php");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
            "url=".$url."&submit=Make TinyURL!");
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    if (empty($html)) {
      return "<strong>Error:</strong> Connection Timeout";
    }
    $html = curl_exec ($ch);
    
    preg_match_all ('/\<b\>(http\:\/\/[^\>]+)\<\/b\>/', $html, $matches);
    $matches = $matches[1];

    foreach($matches as $var) {    
      if (strpos($var, "http://tinyurl.com/") === 0) {
        curl_close ($ch);
        return $var;
      }
    }
  }
  
  
  function get_hugeurl_wiggy($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"http://hugeurl.wiggy.net/stretch");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
            "url=".$url."&filter=MD5&submit=Streeeetch");
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);

    $html = curl_exec ($ch);
    if (empty($html)) {
      return "<strong>Error:</strong> Connection Timeout";
    }
    
    preg_match_all ("/a[\s]+[^>]*?href[\s]?=[\s\"\']+".
                    "(.*?)[\"\']+.*?>"."([^<]+|.*?)?<\/a>/", 
                    $html, $matches);
    $matches = $matches[1];
    
    foreach($matches as $var) {    
      if (strpos($var, "http://hugeurl.wiggy.net") === 0) {
        curl_close ($ch);
        return $var;
      }
    }
  }
  
  function get_hugeurl($url) {

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"http://hugeurl.com/");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
            "encode_url=".$url."&submit=");
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);

    $html = curl_exec ($ch);
    if (empty($html)) {
      return "<strong>Error:</strong> Connection Timeout";
    }
    preg_match_all ("/\<TT\>[^\>]*\<A[^\>]+HREF=\'([^\']+)\'[^\>]*\>/", 
                    $html, $matches);
    $matches = $matches[1];

    foreach($matches as $var) {    
      if (strpos($var, "http://www.hugeurl.com") === 0) {
        curl_close ($ch);
        $url = chunk_split($var, 100);
        
        $var = "<div style='font-family: courier;'><a href=\"".$var."\">{$url}</a></div>";
        return $var;
      }
    }
  }  
?>